package com.sophialex.health.record.common.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

/**
 * <p>
 * Title:Health
 * </p>
 * <p>
 * HealthRecordListenerRegister
 * </p>
 * Alex May 6, 2011 4:27:55 PM create
 * 
 * @author <a href='wanghao924@126.com'>Alex</a> QQ: 873987060;
 * @version 1.0
 */
public class HealthRecordListenerRegister {
	
    private static HealthRecordListenerRegister register = new HealthRecordListenerRegister();
    private HealthRecordListenerRegister(){}
    
    public static HealthRecordListenerRegister getInstance(){
    	return register;
    }
	private List<IPropertyChangeListener> myListeners = new ArrayList<IPropertyChangeListener>();

	public void addPropertyChangeListener(IPropertyChangeListener listener) {
		if(!myListeners.contains(listener))
			myListeners.add(listener);
	}

	public void removePropertyChangeListener(IPropertyChangeListener listener) {
		myListeners.remove(listener);
	}

	public void postEvent(List<IPropertyChangeListener> listeners, Object obj,String eventType) {
		for(Iterator<IPropertyChangeListener> iter = myListeners.iterator(); iter.hasNext();) {
			IPropertyChangeListener element = (IPropertyChangeListener) iter.next();
			element.propertyChange(new PropertyChangeEvent(this,eventType, null, obj));

		}
	}
	public void postEvent(Object obj,String eventType) {
		for(Iterator<IPropertyChangeListener> iter = myListeners.iterator(); iter.hasNext();) {
			IPropertyChangeListener element = (IPropertyChangeListener) iter.next();
			element.propertyChange(new PropertyChangeEvent(this,eventType, null, obj));

		}
	}
}
